{#
/**
 * @file
 * Theme override to display a menu.
 *
 * Available variables:
 * - menu_name: The machine name of the menu.
 * - items: A nested list of menu items. Each menu item contains:
 *   - attributes: HTML attributes for the menu item.
 *   - below: The menu item child items.
 *   - title: The menu link title.
 *   - url: The menu link URL, instance of \Drupal\Core\Url
 *   - localized_options: Menu link localized options.
 *   - is_expanded: TRUE if the link has visible children within the current
 *     menu tree.
 *   - is_collapsed: TRUE if the link has children within the current menu tree
 *     that are not currently visible.
 *   - in_active_trail: TRUE if the link is in the active trail.
 */
#}
{% import _self as menus %}

{#
  We call a macro which calls itself to render the full tree.
  @see https://twig.symfony.com/doc/3.x/tags/macro.html
#}

{{ menus.menu_links(items, 0) }}

{% macro menu_links(items, menu_level) %}
  {% import _self as menus %}
  {% if items %}
    {% if menu_level == 0 %}
      <ul class="header-menu-items">
    {% else %}
      <ul class="header-menu-items">
    {% endif %}
    {% for item in items %}
      {% if item.in_active_trail %}
        <li class="menu-item-active"> {{ link(item.title, item.url) }}
      {% else %}
        <li class="header-menu-item">
          {{ link(item.title, item.url) }}
          {# <a class="" href="{{ item.url }}">{{ item.title }}</a> #}
          {% if item.below %}
            {{ menus.menu_links(item.below, menu_level + 1) }}
          {% endif %}
        </li>
      {% endif %}
    {% endfor %}
    
    {# 搜索图标菜单项 - 新增带li标签的搜索图标 #}
        <li class="header-menu-item search-item">
          <a href="/search/node" class="search-link" aria-label="搜索内容">
            <svg class="size-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="16" height="16">
              <path fill="currentColor" d="M416 208c0 45.9-14.9 88.3-40 122.7L502.6 457.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L330.7 376c-34.4 25.2-76.8 40-122.7 40C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208zM208 352a144 144 0 1 0 0-288 144 144 0 1 0 0 288z"/>
            </svg>
          </a>
        </li>

    </ul>
  {% endif %}
{% endmacro %}

